package com.myjoje.controller;

import com.myjoje.base.BaseController;
import com.myjoje.base.BaseUtil;
import com.myjoje.service.PubService;
import com.myjoje.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 不需要登录可访问
 */
@RestController
@RequestMapping("/pub")
public class PubController {

    @Autowired
    private PubService pubService;


    /**
     * 无权限直接跳转到登录页面
     */
    @RequestMapping("/need_login")
    public Message needLogin() {

        return Message.error("请重新登录");
    }

    /**
     * 验证身份
     */
    @PostMapping("/login")
    public Object validatePrincipal(String username, String password) {
        if (BaseUtil.isEmpty(username)) {
            return Message.error("请输入用户名");
        }
        if (BaseUtil.isEmpty(password)) {
            return Message.error("请输入密码");
        }
        return pubService.validatePrincipal(username, password);
    }

    /**
     * 验证身份
     */
    @RequestMapping("/test")
    public Object test(String username, String password) {

        return Message.success();
    }


}
